#ifndef ITHREAD_H
#define ITHREAD_H

#include "imutex.h"

#define ERR_ITHREAD_CANTINITMUTEX		-1
#define ERR_ITHREAD_CANTSTARTTHREAD		-2
#define ERR_ITHREAD_THREADFUNCNOTSET	-3
#define ERR_ITHREAD_NOTRUNNING			-4
#define ERR_ITHREAD_ALREADYRUNNING		-5

class IThread
{
public:
	IThread();
	virtual ~IThread();

	int Start();
	int Kill();
	virtual void *Thread() = 0;
	bool IsRunning();
	void *GetReturnValue();

protected:
	void ThreadStarted();

private:
#ifdef WIN32
	static UINT __stdcall TheThread(void *param);
	UINT threadid;
	HANDLE threadhandle;
#else
	static void *TheThread(void *param);
	pthread_t threadid;
#endif

	void *retval;
	bool running;
	
	IMutex runningmutex;
	IMutex continuemutex,continuemutex2;
	bool mutexinit;
};

#endif // JTHREAD_H

